package com.dries.portal.module.pay.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dries.common.api.CommonResult;
import com.dries.portal.module.pay.config.WxPayProperties;
import com.dries.portal.module.pay.entity.CashDraws;
import com.dries.portal.module.pay.service.ICashDrawsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * 提现记录表
 *
 * @author dries
 * @email samphsanie@gmail.com
 * @date 2020-09-10 15:55:52
 */
@RestController
@RequestMapping("cashdraws")
public class CashDrawsController {

    @Resource
    private WxPayProperties payProperties;
    @Resource
    private ICashDrawsService cashDrawsService;

    /**
     * 查询提现列表
     */
    @GetMapping("/list/{openId}")
    public CommonResult list(@PathVariable String openId,
                             @RequestParam(defaultValue = "10", required = false) Integer pageSize,
                             @RequestParam(defaultValue = "1", required = false) Integer pageNum){

        PageHelper.startPage(pageNum, pageSize);

        List<CashDraws> list = cashDrawsService.list(new QueryWrapper<CashDraws>().lambda()
                .eq(CashDraws::getTargetId, openId)
                .orderByDesc(CashDraws::getCreateTime)
        );

        return CommonResult.success(new PageInfo<>(list));
    }


    /**
     * 查询提现信息
     */
    @GetMapping("/info/{cashId}")
    public CommonResult info(@PathVariable("cashId") Integer cashId){

		CashDraws cashDraws = cashDrawsService.getById(cashId);
		return cashDrawsService.getCashDrawsInfo(cashDraws);
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public CommonResult delete(@RequestBody Integer[] cashIds){
		cashDrawsService.removeByIds(Arrays.asList(cashIds));

        return CommonResult.success();
    }

}
